﻿using Microsoft.Extensions.Logging;
using Microsoft.Extensions.DependencyInjection;
using Odyssey;
using Odyssey.Application;
using System;
namespace Athena.Performance.Compare.Service
{
    using Models;
    using Options;
    using Transport.DotNetty;
    using Transport.BeetleX;

    class Startup : IStartup
    {
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddLogging();
            services.AddAthenaCore(new ServiceDescriptor()
            {
                Id = "athena.xunit.test",
                Name = "雅典娜RPC-Test"
            }, new AthenaOptions()
            {
                RouteAddressOption = new RouteAddressOption()
                {
                    FileServiceMultipleRouteDirectory = "C:\\athena\\routes"
                }
            });
            services.AddServiceRuntimeCore();
            services.AddRouteCore();
            //services.AddFileRouteManager();
            //services.AddBeetleXTransport();
            services.AddDotNettyTransport();
            services.AddSingleton<IUser, UserDispatch>();
            return services.BuildServiceProvider();
        }

        public void Configure(IServiceProvider serviceProvider)
        {
            var logger = serviceProvider.GetRequiredService<ILogger<Startup>>();
            serviceProvider.UseService();
            serviceProvider.GetRequiredService<IApplicationLifetime>().ApplicationStarted.Register(() =>
            {
                logger.LogInformation("Athena RPC Service Ready");
            });
        }
    }
}
